from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-06 14:14:54.226678
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 06, Oct, 2022
Time: 14:15:00
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.6189
Nobs: 801.000 HQIC: -50.9432
Log likelihood: 10344.6 FPE: 6.13512e-23
AIC: -51.1454 Det(Omega_mle): 5.48692e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297938 0.052899 5.632 0.000
L1.Burgenland 0.108987 0.035566 3.064 0.002
L1.Kärnten -0.106434 0.018934 -5.621 0.000
L1.Niederösterreich 0.209446 0.074362 2.817 0.005
L1.Oberösterreich 0.101169 0.071380 1.417 0.156
L1.Salzburg 0.251607 0.037919 6.635 0.000
L1.Steiermark 0.038044 0.049632 0.767 0.443
L1.Tirol 0.106387 0.040228 2.645 0.008
L1.Vorarlberg -0.059154 0.034589 -1.710 0.087
L1.Wien 0.056482 0.063779 0.886 0.376
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064204 0.109534 0.586 0.558
L1.Burgenland -0.033618 0.073644 -0.456 0.648
L1.Kärnten 0.047837 0.039205 1.220 0.222
L1.Niederösterreich -0.172131 0.153976 -1.118 0.264
L1.Oberösterreich 0.385039 0.147802 2.605 0.009
L1.Salzburg 0.287199 0.078516 3.658 0.000
L1.Steiermark 0.106336 0.102769 1.035 0.301
L1.Tirol 0.313450 0.083298 3.763 0.000
L1.Vorarlberg 0.025292 0.071621 0.353 0.724
L1.Wien -0.016959 0.132063 -0.128 0.898
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190190 0.027169 7.000 0.000
L1.Burgenland 0.090010 0.018266 4.928 0.000
L1.Kärnten -0.008423 0.009724 -0.866 0.386
L1.Niederösterreich 0.263940 0.038192 6.911 0.000
L1.Oberösterreich 0.127019 0.036660 3.465 0.001
L1.Salzburg 0.047189 0.019475 2.423 0.015
L1.Steiermark 0.016960 0.025490 0.665 0.506
L1.Tirol 0.094163 0.020661 4.558 0.000
L1.Vorarlberg 0.059303 0.017765 3.338 0.001
L1.Wien 0.120687 0.032756 3.684 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109801 0.027836 3.945 0.000
L1.Burgenland 0.044362 0.018715 2.370 0.018
L1.Kärnten -0.016083 0.009963 -1.614 0.106
L1.Niederösterreich 0.192988 0.039129 4.932 0.000
L1.Oberösterreich 0.293661 0.037560 7.818 0.000
L1.Salzburg 0.114836 0.019953 5.755 0.000
L1.Steiermark 0.100295 0.026116 3.840 0.000
L1.Tirol 0.116210 0.021168 5.490 0.000
L1.Vorarlberg 0.070858 0.018201 3.893 0.000
L1.Wien -0.027273 0.033561 -0.813 0.416
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.128772 0.050481 2.551 0.011
L1.Burgenland -0.051246 0.033940 -1.510 0.131
L1.Kärnten -0.040262 0.018068 -2.228 0.026
L1.Niederösterreich 0.170274 0.070962 2.399 0.016
L1.Oberösterreich 0.136792 0.068117 2.008 0.045
L1.Salzburg 0.285207 0.036185 7.882 0.000
L1.Steiermark 0.035306 0.047363 0.745 0.456
L1.Tirol 0.164102 0.038389 4.275 0.000
L1.Vorarlberg 0.104160 0.033008 3.156 0.002
L1.Wien 0.069176 0.060863 1.137 0.256
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060082 0.040009 1.502 0.133
L1.Burgenland 0.038499 0.026899 1.431 0.152
L1.Kärnten 0.050636 0.014320 3.536 0.000
L1.Niederösterreich 0.225708 0.056241 4.013 0.000
L1.Oberösterreich 0.281814 0.053986 5.220 0.000
L1.Salzburg 0.050919 0.028679 1.776 0.076
L1.Steiermark -0.006617 0.037537 -0.176 0.860
L1.Tirol 0.149892 0.030426 4.927 0.000
L1.Vorarlberg 0.071176 0.026160 2.721 0.007
L1.Wien 0.078859 0.048237 1.635 0.102
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.178674 0.047828 3.736 0.000
L1.Burgenland -0.005859 0.032157 -0.182 0.855
L1.Kärnten -0.061057 0.017119 -3.567 0.000
L1.Niederösterreich -0.083280 0.067234 -1.239 0.215
L1.Oberösterreich 0.192419 0.064538 2.981 0.003
L1.Salzburg 0.056476 0.034284 1.647 0.100
L1.Steiermark 0.231127 0.044874 5.151 0.000
L1.Tirol 0.493538 0.036372 13.569 0.000
L1.Vorarlberg 0.049454 0.031274 1.581 0.114
L1.Wien -0.049118 0.057666 -0.852 0.394
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161475 0.054903 2.941 0.003
L1.Burgenland -0.011020 0.036913 -0.299 0.765
L1.Kärnten 0.065992 0.019651 3.358 0.001
L1.Niederösterreich 0.201084 0.077179 2.605 0.009
L1.Oberösterreich -0.061642 0.074085 -0.832 0.405
L1.Salzburg 0.215757 0.039355 5.482 0.000
L1.Steiermark 0.114042 0.051512 2.214 0.027
L1.Tirol 0.076685 0.041753 1.837 0.066
L1.Vorarlberg 0.124314 0.035900 3.463 0.001
L1.Wien 0.115496 0.066196 1.745 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.354532 0.031927 11.105 0.000
L1.Burgenland 0.005991 0.021465 0.279 0.780
L1.Kärnten -0.023507 0.011427 -2.057 0.040
L1.Niederösterreich 0.223563 0.044880 4.981 0.000
L1.Oberösterreich 0.176476 0.043081 4.096 0.000
L1.Salzburg 0.046904 0.022885 2.050 0.040
L1.Steiermark -0.018101 0.029955 -0.604 0.546
L1.Tirol 0.108568 0.024279 4.472 0.000
L1.Vorarlberg 0.073303 0.020876 3.511 0.000
L1.Wien 0.053551 0.038493 1.391 0.164
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041177 0.152781 0.190922 0.157698 0.125171 0.113919 0.065786 0.226639
Kärnten 0.041177 1.000000 -0.002430 0.129759 0.041537 0.096030 0.429717 -0.053222 0.101528
Niederösterreich 0.152781 -0.002430 1.000000 0.337611 0.155696 0.300265 0.111037 0.183375 0.327689
Oberösterreich 0.190922 0.129759 0.337611 1.000000 0.232800 0.332328 0.172540 0.171963 0.264216
Salzburg 0.157698 0.041537 0.155696 0.232800 1.000000 0.146056 0.127055 0.148684 0.136716
Steiermark 0.125171 0.096030 0.300265 0.332328 0.146056 1.000000 0.153219 0.140877 0.080477
Tirol 0.113919 0.429717 0.111037 0.172540 0.127055 0.153219 1.000000 0.114695 0.155421
Vorarlberg 0.065786 -0.053222 0.183375 0.171963 0.148684 0.140877 0.114695 1.000000 0.007217
Wien 0.226639 0.101528 0.327689 0.264216 0.136716 0.080477 0.155421 0.007217 1.000000